"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.simpleCollisionDetection = exports.distance = exports.randomColor = exports.randomChineseName = void 0;
const NAMES = [
    '断笔画墨',
    '默然相爱',
    '旅人不扰',
    '多余温情',
    '云中谁忆',
    '残雪冰心',
    '末世岛屿',
    '桑榆非晚',
    '扉匣与桔',
    '木槿暖夏',
    '空城旧梦',
];
function color16() {
    const r = Math.floor(Math.random() * 256);
    const g = Math.floor(Math.random() * 256);
    const b = Math.floor(Math.random() * 256);
    // const color = '#' + r.toString(16) + g.toString(16) + b.toString(16);
    const color = '#' + (Array(6).join('0') + (r.toString(16) + g.toString(16) + b.toString(16))).slice(-6);
    return color;
}
/**
 * 随机的中文名
 */
function randomChineseName() {
    return NAMES[~~(NAMES.length * Math.random())];
}
exports.randomChineseName = randomChineseName;
/**
 * 随机颜色
 */
function randomColor() {
    return color16();
}
exports.randomColor = randomColor;
/**
 * 两点距离
 * @param x1
 * @param y1
 * @param x2
 * @param y2
 */
function distance(x1, y1, x2, y2) {
    let dx = Math.abs(x1 - x2);
    let dy = Math.abs(y1 - y2);
    return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
}
exports.distance = distance;
/**
 * 简单碰撞检测
 * @param x1
 * @param y1
 * @param x2
 * @param y2
 * @param distance
 */
function simpleCollisionDetection(x1, y1, x2, y2, distance) {
    let dx = Math.abs(x1 - x2);
    let dy = Math.abs(y1 - y2);
    if (dx > distance || dy > distance) {
        return false;
    }
    // console.log(x1, x2, y1, y2, distance, '-', dx, dy);
    return Math.pow(distance, 2) > (Math.pow(dx, 2) + Math.pow(dy, 2));
}
exports.simpleCollisionDetection = simpleCollisionDetection;
